﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using CMS.BLL;

public partial class Controls_StaticPages_ctrStaticPages : System.Web.UI.UserControl
{
    private int nPageCount = 0;
    private int nCurrentLanguage = Support.GetCurrentLanguage() -1;
    private int nDefaultLanguage = Support.GetDefaultLanguage();
    private int nPageSize = Config.PAGESIZE;
    private int nPageIndex = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindDataService();
        }
    }
    private void BindDataService()
    {
        string nPages = ConvertData.ConvertToString(Request.QueryString[Config.PAGE]);
        StaticPages objService = new StaticPages();
        DataTable dtbService = new DataTable();
        int nRootParent = ConvertData.ConvertToInt(objService.GetIDbyPageCode(nPages));
        dtbService = objService.Search(string.Empty, nRootParent, nDefaultLanguage, nCurrentLanguage, EnumeType.ACTIVE, nPageIndex, nPageSize, ref nPageCount);

        rptServices.DataSource = dtbService;
        rptServices.DataBind();
        switch (nPages)
        {
            case "services":
                lblTitle.Text = MultipleLanguage.SERVICE[nCurrentLanguage - 1];
                lblMap.Text = MultipleLanguage.SERVICE[nCurrentLanguage - 1];
                break;
            case "consulting":
                lblTitle.Text = MultipleLanguage.CONSULTING[nCurrentLanguage - 1];
                lblMap.Text = MultipleLanguage.CONSULTING[nCurrentLanguage - 1];
                break;

        }
        
        
    }
    protected void rptServices_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblTitleService = (Label)e.Item.FindControl("lblTitleService");
            Literal ltrContentServices = (Literal)e.Item.FindControl("ltrContentServices");
            Image imgServices = (Image)e.Item.FindControl("imgServices");
            HyperLink lnkimgServices = (HyperLink)e.Item.FindControl("lnkimgServices"); 
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "StaticPageID"));
            lblTitleService.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "PageName"));
            ltrContentServices.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent"));
            
            string ImgUrl = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Images"));
            if (ImgUrl == "")
            {
                imgServices.ImageUrl = Config.ROOT + Config.IMAGE_NO_IMAGE_FRONTEND;

            }
            else { imgServices.ImageUrl = Config.ROOT + Config.IMAGE_STATICPAGE_DEFAULT_UPLOAD + ImgUrl; }

            lnkimgServices.NavigateUrl = Config.ROOT + Pages.FrontEnds.STATIC_PAGE + "?" + Config.PAGE_ID + "=" + nID;
        }
    }
    protected void rptServices_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }
}